package com.arrogames.rgblabyrinth.game.graphics {
	import net.pixelpracht.tmx.TmxLayer;
	
	import starling.display.Sprite;
	import starling.events.KeyboardEvent;
	
	public class TiledLayer extends Sprite {
		/** Temporary solution to display different layers */
		private static var nextKey:uint = 49;
		private var myKey:uint;
		
		/** Temporary solution to display different layers */
		
		private var tmxLayer:TmxLayer;
		private var _tiles:Vector.<TmxTile> = new Vector.<TmxTile>();
		
		public function TiledLayer(tmxLayer:TmxLayer) {
			super();
			this.tmxLayer = tmxLayer;
			this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
			myKey = nextKey++;
		}
		
		/** Temporary solution to display different layers */
		private function onKeyUp(event:KeyboardEvent):void {
			
			if (event.keyCode === myKey) {
				var tile:TmxTile;
				
				if (numChildren > 0) {
					for each (tile in _tiles) {
						removeChild(tile);
					}
				} else {
					for each (tile in _tiles) {
						addChild(tile);
					}
				}
			}
		}
		/** Temporary solution to display different layers */
		
		public function addTile(tile:TmxTile):void {
			_tiles.push(tile);
			addChild(tile);
		}
	}
}